package com.yuyu.storage.api;

import com.yuyu.commons.interceptor.response.ResponseJson;
import com.yuyu.storage.domin.Do.GoodsStockDO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author
 * @version 1.0
 * @description: 仓库相关controller
 * @date 2022/12/8 14:46
 */
@RestController
@RequestMapping("/repository")
public class StorageController {

    @GetMapping("/getStock")
    public ResponseJson<Long> getStock(@RequestParam("goodsId") Long goodsId){
        GoodsStockDO goodsStockDO = new GoodsStockDO();
        Long stockNum = goodsStockDO.getStockNum(goodsId);
        return ResponseJson.success(stockNum);
    }

    @GetMapping("/decrStock")
    public ResponseJson<Boolean> decStock(@RequestParam("goodsId") Long goodsId,
                                           @RequestParam("stockNum")Long stockNum){
        GoodsStockDO goodsStockDO = new GoodsStockDO();
        Boolean aBoolean = goodsStockDO.descStockNum(goodsId, stockNum);
        return ResponseJson.success(aBoolean);
    }

    @GetMapping("/frozenStock")
    public ResponseJson<Boolean> rollBackStock(@RequestParam("goodsId")Long goodsId,
                                             @RequestParam("stockNum")Long stockNum){
        GoodsStockDO goodsStockDO = new GoodsStockDO();
        goodsStockDO.rollBackStock(goodsId, stockNum);
        return ResponseJson.success(Boolean.TRUE);
    }
}
